/**
 * http://usejsdoc.org/
 */
/**
 * 路由转换
 * @param req
 * @param res
 * @param pathname 路径名称
 */
exports.router = function(res,req){
	var pathname = decodeURI(lib.url.parse(req.url).pathname);
	lib.httpParam.init(res,req);
	var model = pathname.substring(1,pathname.lastIndexOf('/')),
		//controller = httpParam.GET('c'),
		controller = pathname.substring(pathname.lastIndexOf('/')+1),
		Class = '';
	if (pathname ===  '/favicon.ico') {//忽略/favicon.ico请求
		return;
	}else if(pathname === '/' || pathname === '/index'){//默认进入首页
		res.render(VIEW + 'index.jade',{username:"devintam"});
		return;
	}else {
		try {
			Class = require(global.CON + model);
		} catch (e) {
			lib.staticModule.getStaticFile(pathname,res,req);
			return;
		}
		if(Class){//require成功时，应用call方法，实现类中的方法调用执行
			try {
				var classObject = new Class(res,req);
				classObject[controller].call();
			} catch (e) {
				console.log(e);
				res.writeHead( 404 , {"Content-Type":"text/plain"});
				res.end('can not find source!');
			}
		}else{//调用不存在的模块时，则默认返回404错误
			res.writeHead( 404 , {"Content-Type":"text/plain"});
			res.end('can not find source!');
		}
	}
};